/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package system.impl;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import system.CascadeOperations;
import system.Entity;
import system.FetchType;
import system.Multiplicity;
import system.Reference;
import system.SystemPackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Reference</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link system.impl.ReferenceImpl#getReferencedEntity <em>Referenced Entity</em>}</li>
 *   <li>{@link system.impl.ReferenceImpl#getMultiplicity <em>Multiplicity</em>}</li>
 *   <li>{@link system.impl.ReferenceImpl#getCascade <em>Cascade</em>}</li>
 *   <li>{@link system.impl.ReferenceImpl#getMappedBy <em>Mapped By</em>}</li>
 *   <li>{@link system.impl.ReferenceImpl#getFetchType <em>Fetch Type</em>}</li>
 *   <li>{@link system.impl.ReferenceImpl#getJoinColumnName <em>Join Column Name</em>}</li>
 *   <li>{@link system.impl.ReferenceImpl#getJoinTableName <em>Join Table Name</em>}</li>
 *   <li>{@link system.impl.ReferenceImpl#getInverseJoinColumnName <em>Inverse Join Column Name</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ReferenceImpl extends NamedClassImpl implements Reference {
	/**
	 * The cached value of the '{@link #getReferencedEntity() <em>Referenced Entity</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getReferencedEntity()
	 * @generated
	 * @ordered
	 */
	protected Entity referencedEntity;

	/**
	 * The default value of the '{@link #getMultiplicity() <em>Multiplicity</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMultiplicity()
	 * @generated
	 * @ordered
	 */
	protected static final Multiplicity MULTIPLICITY_EDEFAULT = Multiplicity.ONE_TO_ONE;

	/**
	 * The cached value of the '{@link #getMultiplicity() <em>Multiplicity</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMultiplicity()
	 * @generated
	 * @ordered
	 */
	protected Multiplicity multiplicity = MULTIPLICITY_EDEFAULT;

	/**
	 * The default value of the '{@link #getCascade() <em>Cascade</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCascade()
	 * @generated
	 * @ordered
	 */
	protected static final CascadeOperations CASCADE_EDEFAULT = CascadeOperations.ALL;

	/**
	 * The cached value of the '{@link #getCascade() <em>Cascade</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getCascade()
	 * @generated
	 * @ordered
	 */
	protected CascadeOperations cascade = CASCADE_EDEFAULT;

	/**
	 * The default value of the '{@link #getMappedBy() <em>Mapped By</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMappedBy()
	 * @generated
	 * @ordered
	 */
	protected static final String MAPPED_BY_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getMappedBy() <em>Mapped By</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMappedBy()
	 * @generated
	 * @ordered
	 */
	protected String mappedBy = MAPPED_BY_EDEFAULT;

	/**
	 * The default value of the '{@link #getFetchType() <em>Fetch Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFetchType()
	 * @generated
	 * @ordered
	 */
	protected static final FetchType FETCH_TYPE_EDEFAULT = FetchType.EAGER;

	/**
	 * The cached value of the '{@link #getFetchType() <em>Fetch Type</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFetchType()
	 * @generated
	 * @ordered
	 */
	protected FetchType fetchType = FETCH_TYPE_EDEFAULT;

	/**
	 * The default value of the '{@link #getJoinColumnName() <em>Join Column Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getJoinColumnName()
	 * @generated
	 * @ordered
	 */
	protected static final String JOIN_COLUMN_NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getJoinColumnName() <em>Join Column Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getJoinColumnName()
	 * @generated
	 * @ordered
	 */
	protected String joinColumnName = JOIN_COLUMN_NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getJoinTableName() <em>Join Table Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getJoinTableName()
	 * @generated
	 * @ordered
	 */
	protected static final String JOIN_TABLE_NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getJoinTableName() <em>Join Table Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getJoinTableName()
	 * @generated
	 * @ordered
	 */
	protected String joinTableName = JOIN_TABLE_NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getInverseJoinColumnName() <em>Inverse Join Column Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInverseJoinColumnName()
	 * @generated
	 * @ordered
	 */
	protected static final String INVERSE_JOIN_COLUMN_NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getInverseJoinColumnName() <em>Inverse Join Column Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getInverseJoinColumnName()
	 * @generated
	 * @ordered
	 */
	protected String inverseJoinColumnName = INVERSE_JOIN_COLUMN_NAME_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ReferenceImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return SystemPackage.Literals.REFERENCE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Entity getReferencedEntity() {
		if (referencedEntity != null && referencedEntity.eIsProxy()) {
			InternalEObject oldReferencedEntity = (InternalEObject)referencedEntity;
			referencedEntity = (Entity)eResolveProxy(oldReferencedEntity);
			if (referencedEntity != oldReferencedEntity) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, SystemPackage.REFERENCE__REFERENCED_ENTITY, oldReferencedEntity, referencedEntity));
			}
		}
		return referencedEntity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Entity basicGetReferencedEntity() {
		return referencedEntity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setReferencedEntity(Entity newReferencedEntity) {
		Entity oldReferencedEntity = referencedEntity;
		referencedEntity = newReferencedEntity;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SystemPackage.REFERENCE__REFERENCED_ENTITY, oldReferencedEntity, referencedEntity));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Multiplicity getMultiplicity() {
		return multiplicity;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMultiplicity(Multiplicity newMultiplicity) {
		Multiplicity oldMultiplicity = multiplicity;
		multiplicity = newMultiplicity == null ? MULTIPLICITY_EDEFAULT : newMultiplicity;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SystemPackage.REFERENCE__MULTIPLICITY, oldMultiplicity, multiplicity));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public CascadeOperations getCascade() {
		return cascade;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setCascade(CascadeOperations newCascade) {
		CascadeOperations oldCascade = cascade;
		cascade = newCascade == null ? CASCADE_EDEFAULT : newCascade;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SystemPackage.REFERENCE__CASCADE, oldCascade, cascade));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getMappedBy() {
		return mappedBy;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMappedBy(String newMappedBy) {
		String oldMappedBy = mappedBy;
		mappedBy = newMappedBy;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SystemPackage.REFERENCE__MAPPED_BY, oldMappedBy, mappedBy));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public FetchType getFetchType() {
		return fetchType;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFetchType(FetchType newFetchType) {
		FetchType oldFetchType = fetchType;
		fetchType = newFetchType == null ? FETCH_TYPE_EDEFAULT : newFetchType;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SystemPackage.REFERENCE__FETCH_TYPE, oldFetchType, fetchType));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getJoinColumnName() {
		return joinColumnName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setJoinColumnName(String newJoinColumnName) {
		String oldJoinColumnName = joinColumnName;
		joinColumnName = newJoinColumnName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SystemPackage.REFERENCE__JOIN_COLUMN_NAME, oldJoinColumnName, joinColumnName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getJoinTableName() {
		return joinTableName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setJoinTableName(String newJoinTableName) {
		String oldJoinTableName = joinTableName;
		joinTableName = newJoinTableName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SystemPackage.REFERENCE__JOIN_TABLE_NAME, oldJoinTableName, joinTableName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getInverseJoinColumnName() {
		return inverseJoinColumnName;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setInverseJoinColumnName(String newInverseJoinColumnName) {
		String oldInverseJoinColumnName = inverseJoinColumnName;
		inverseJoinColumnName = newInverseJoinColumnName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, SystemPackage.REFERENCE__INVERSE_JOIN_COLUMN_NAME, oldInverseJoinColumnName, inverseJoinColumnName));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case SystemPackage.REFERENCE__REFERENCED_ENTITY:
				if (resolve) return getReferencedEntity();
				return basicGetReferencedEntity();
			case SystemPackage.REFERENCE__MULTIPLICITY:
				return getMultiplicity();
			case SystemPackage.REFERENCE__CASCADE:
				return getCascade();
			case SystemPackage.REFERENCE__MAPPED_BY:
				return getMappedBy();
			case SystemPackage.REFERENCE__FETCH_TYPE:
				return getFetchType();
			case SystemPackage.REFERENCE__JOIN_COLUMN_NAME:
				return getJoinColumnName();
			case SystemPackage.REFERENCE__JOIN_TABLE_NAME:
				return getJoinTableName();
			case SystemPackage.REFERENCE__INVERSE_JOIN_COLUMN_NAME:
				return getInverseJoinColumnName();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case SystemPackage.REFERENCE__REFERENCED_ENTITY:
				setReferencedEntity((Entity)newValue);
				return;
			case SystemPackage.REFERENCE__MULTIPLICITY:
				setMultiplicity((Multiplicity)newValue);
				return;
			case SystemPackage.REFERENCE__CASCADE:
				setCascade((CascadeOperations)newValue);
				return;
			case SystemPackage.REFERENCE__MAPPED_BY:
				setMappedBy((String)newValue);
				return;
			case SystemPackage.REFERENCE__FETCH_TYPE:
				setFetchType((FetchType)newValue);
				return;
			case SystemPackage.REFERENCE__JOIN_COLUMN_NAME:
				setJoinColumnName((String)newValue);
				return;
			case SystemPackage.REFERENCE__JOIN_TABLE_NAME:
				setJoinTableName((String)newValue);
				return;
			case SystemPackage.REFERENCE__INVERSE_JOIN_COLUMN_NAME:
				setInverseJoinColumnName((String)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case SystemPackage.REFERENCE__REFERENCED_ENTITY:
				setReferencedEntity((Entity)null);
				return;
			case SystemPackage.REFERENCE__MULTIPLICITY:
				setMultiplicity(MULTIPLICITY_EDEFAULT);
				return;
			case SystemPackage.REFERENCE__CASCADE:
				setCascade(CASCADE_EDEFAULT);
				return;
			case SystemPackage.REFERENCE__MAPPED_BY:
				setMappedBy(MAPPED_BY_EDEFAULT);
				return;
			case SystemPackage.REFERENCE__FETCH_TYPE:
				setFetchType(FETCH_TYPE_EDEFAULT);
				return;
			case SystemPackage.REFERENCE__JOIN_COLUMN_NAME:
				setJoinColumnName(JOIN_COLUMN_NAME_EDEFAULT);
				return;
			case SystemPackage.REFERENCE__JOIN_TABLE_NAME:
				setJoinTableName(JOIN_TABLE_NAME_EDEFAULT);
				return;
			case SystemPackage.REFERENCE__INVERSE_JOIN_COLUMN_NAME:
				setInverseJoinColumnName(INVERSE_JOIN_COLUMN_NAME_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case SystemPackage.REFERENCE__REFERENCED_ENTITY:
				return referencedEntity != null;
			case SystemPackage.REFERENCE__MULTIPLICITY:
				return multiplicity != MULTIPLICITY_EDEFAULT;
			case SystemPackage.REFERENCE__CASCADE:
				return cascade != CASCADE_EDEFAULT;
			case SystemPackage.REFERENCE__MAPPED_BY:
				return MAPPED_BY_EDEFAULT == null ? mappedBy != null : !MAPPED_BY_EDEFAULT.equals(mappedBy);
			case SystemPackage.REFERENCE__FETCH_TYPE:
				return fetchType != FETCH_TYPE_EDEFAULT;
			case SystemPackage.REFERENCE__JOIN_COLUMN_NAME:
				return JOIN_COLUMN_NAME_EDEFAULT == null ? joinColumnName != null : !JOIN_COLUMN_NAME_EDEFAULT.equals(joinColumnName);
			case SystemPackage.REFERENCE__JOIN_TABLE_NAME:
				return JOIN_TABLE_NAME_EDEFAULT == null ? joinTableName != null : !JOIN_TABLE_NAME_EDEFAULT.equals(joinTableName);
			case SystemPackage.REFERENCE__INVERSE_JOIN_COLUMN_NAME:
				return INVERSE_JOIN_COLUMN_NAME_EDEFAULT == null ? inverseJoinColumnName != null : !INVERSE_JOIN_COLUMN_NAME_EDEFAULT.equals(inverseJoinColumnName);
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (multiplicity: ");
		result.append(multiplicity);
		result.append(", cascade: ");
		result.append(cascade);
		result.append(", mappedBy: ");
		result.append(mappedBy);
		result.append(", fetchType: ");
		result.append(fetchType);
		result.append(", joinColumnName: ");
		result.append(joinColumnName);
		result.append(", joinTableName: ");
		result.append(joinTableName);
		result.append(", inverseJoinColumnName: ");
		result.append(inverseJoinColumnName);
		result.append(')');
		return result.toString();
	}

} //ReferenceImpl
